import { updateUserPointService } from '../service/users'
import { useUserStore } from '../store'
import { IconPath, type IconPathType } from './icon-path'
import { PagePath } from './page-path'
import type { PageTitleType } from './page-title'
import { Menu } from '@/common/constants/menu'

/**
 * 导航项类型
 * @author lian
 */
export interface NavigateItemType {
  icon: IconPathType
  title: PageTitleType
  onClick: () => void
}

/**
 * 签到
 * @author lian
 */
const everydaySignIn = () => {
  uni.showModal({
    title: '每日小知识',
    content: '你好世界',
    confirmText: '签到',
    success(result) {
      if (result.confirm) {
        // 更新用户积分
        updateUserPointService(1).then((res) => {
          showSimpleToast(res.data ? SIGN_IN_SUCCESS : ALREADY_SIGN_IN)
        }).catch(() => {
          showSimpleToast(SIGN_IN_FAIL)
        })
      }
    },
  })
}

/**
 * 导航项
 * @author lian
 */
export const NavigateItem: Record<string, NavigateItemType> = {
  CALENDAR: {
    icon: IconPath.CALENDAR,
    title: Menu.SIGN_IN,
    onClick: () => everydaySignIn(),
  },
  MY_PROJECT: {
    icon: IconPath.PROJECTS,
    title: Menu.MY_PROJECT,
    onClick: () => goToPage(PagePath.MY_LIST_PROJECT),
  },
  MY_ACTIVITY: {
    icon: IconPath.VOLUNTEER,
    title: Menu.MY_ACTIVITY,
    onClick: () => goToPage(PagePath.MY_LIST_ACTIVITY),
  },
  NOTIFICATION: {
    icon: IconPath.NOTIFICATION,
    title: Menu.NOTIFICATION,
    onClick: () => goToPage(PagePath.NOTIFICATION),
  },
  DYNAMIC: {
    icon: IconPath.DYNAMIC,
    title: Menu.MY_DYNAMIC,
    onClick: () => goToPage(PagePath.MY_LIST_DYNAMIC),
  },
}
